package Week3.J0429;

import java.util.Scanner;

public class 牛牛冲钻五 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int sum = 0;
            int count = 0;
            int session = scanner.nextInt();
            int bonus = scanner.nextInt(); // 三连胜加bonus颗星
            char[] match = scanner.next().toCharArray();

            for (int j = 0; j < session; j++) {
                if (match[j] == 'W' && count >= 2) {
                    sum += bonus;
                }
                if (match[j] == 'W' && count < 2) {
                    count++;
                    sum++;
                }
                if (match[j] == 'L') {
                    sum--;
                    count = 0;
                }
            }
            System.out.println(sum);

        }
    }
}
